<template>
    <h3>添加投资信息</h3>
    <table>
        <tr>
            <td>投资名称：</td>
            <td><input type="text" v-model="I_Name"></td>
        </tr>
        <tr>
            <td>投资总额：</td>
            <td><input type="text" v-model="PriceAll"></td>
        </tr>
        <tr>
            <td colspan="2"><button @click="AddInvest">添加投资信息</button></td>
        </tr>
    </table>
</template>
<script setup lang="ts">
import { ref } from 'vue'
import axios from 'axios'
import { useRouter } from 'vue-router';


const I_Name = ref("");
const PriceAll = ref();

const AddInvest = () => {
    axios.post('http://localhost:65052/api/Invest/AddInvest', {
        I_Name: I_Name.value,
        PriceAll: PriceAll.value
    })
        .then(res => {
            if (res.data > 0) {
                alert("添加成功");
                Jump();
            }
            else {
                alert("添加失败")
                return;
            }
        })
        .catch(error => {
            console.log(error);
        })
}

const router = useRouter();
const Jump = () => {
    router.push({
        name: '/InvestShow',
        params: {
            I_Name: I_Name.value,
            PriceAll: PriceAll.value
        }
    })
}
</script>